<template>
  <div id="app">
    <h1>根组件{{ $store.state.count }}</h1>
    <input type="text" @input="change" :value="$store.state.count" />
    <add-item></add-item>
    <hr />
    <sub-item></sub-item>
  </div>
</template>

<script>
import AddItem from "./components/add-item.vue";
import SubItem from "./components/sub-item.vue";
import { mapMutations } from "vuex";
export default {
  name: "app",
  data: function () {
    return {};
  },
  components: {
    AddItem,
    SubItem,
  },
  methods: {
    // 展开了获取里面的函数
    ...mapMutations(["changeCount"]),
    change(e) {
      // console.log(e.target.value);
      // 触发changeCount执行把传的参数，传给第二个参数num
      // this.$store.commit('changeCount',+e.target.value)
      // 直接调用
      this.changeCount(e.target.value);
    },
  },
};
</script>

<style>
#app {
  width: 600px;
  margin: 20px auto;
  border: 3px solid #ccc;
  border-radius: 3px;
  padding: 10px;
}
</style>